home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / falcon / nt_dsp1.lzh / NT_DSP1.MSA / MATRIX / MATMUL3.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-01-24  |  2.8 KB  |  81 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; General Matrix Multiply-Accumulate, C=AB+Q
  6. ; Last Update 04 Feb 87   Version 1.0
  7. ;
  8.         opt     cex
  9.         page    132,66,0,0
  10. ;
  11. ;       matrix multiply
  12. ;
  13. ;       Implements the matrix operation C=AB+Q
  14. ;
  15. ;       A 2x3
  16. mw      equ     2
  17. mx      equ     3
  18. ;       B 3x5
  19. my      equ     3
  20. mz      equ     5
  21. ;
  22. ;
  23. ;
  24.         org     x:0
  25. mat_a                           ; A matrix 2x3
  26.         dc        .4                    ;a(1,1)
  27.         dc        .3                    ;a(1,2)
  28.         dc        -.6                   ;a(1,3)
  29.         dc       .15                    ;a(2,1)
  30.         dc       -.8                    ;a(2,2)
  31.         dc       .25                    ;a(2,3)
  32.  
  33.         org     y:0
  34. mat_b                           ; B matrix 3x5
  35.         dc        -.4                   ;b(1,1)
  36.         dc        .35                   ;b(1,2)
  37.         dc       .15                    ;b(1,3)
  38.         dc        -.4                   ;b(1,4)
  39.         dc       .2                     ;b(1,5)
  40.         dc        .5                    ;b(2,1)
  41.         dc       -.3                    ;b(2,2)
  42.         dc       .4                     ;b(2,3)
  43.         dc        .1                    ;b(2,4)
  44.         dc       -.15                   ;b(2,5)
  45.         dc        .6                    ;b(3,1)
  46.         dc        -.35                  ;b(3,2)
  47.         dc       .45                    ;b(3,3)
  48.         dc        .25                   ;b(3,4)
  49.         dc        .2                    ;b(3,5)
  50.  
  51. mat_c   ds      mw*mz           ;output C martix 2x5
  52. mat_q   bsc     mw*mz,$200000   ;X array to add
  53. ;
  54. ;       matrix multiply for row major storage format
  55. ;
  56.         org     p:$100
  57. matmul  move    #mat_a,r0       ;point to A matrix
  58.         move    #mat_q,r2       ;matrix to add
  59.         move    #mat_b,r4       ;point to B matrix
  60.         move    #mat_c,r6       ;output to C matrix
  61.         move    #my,n0          ;second dimension of A
  62.         move    #mz,n5          ;second dimension of B
  63.  
  64.         do      #mw,_ew         ;number of final rows
  65.         do      #mz,_ez         ;number of final columns
  66.         move    r0,r1           ; copy ptr
  67.         move    r4,r5           ;copy second ptr
  68.         move    y:(r2)+,a       ;load element of X to add to
  69.         move    x:(r1)+,x0  y:(r5)+n5,y0        
  70.         rep     #my-1           ;inner sum
  71.         mac     x0,y0,a  x:(r1)+,x0  y:(r5)+n5,y0
  72.         macr    x0,y0,a   (r4)+ ;move to next column in B
  73.         move    a,y:(r6)+       ;save result
  74. _ez
  75.         move    (r0)+n0         ;move to next row in A
  76.         move    #mat_b,r4       ;point back to first column in B
  77. _ew
  78.         end
  79.